﻿namespace WPForms.Common.Model
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Text;

    /// <summary>
    /// Partial class for FormElement to be decorated with KnownType attributes.
    /// </summary>
    [KnownType(typeof(DateTimeField))]
    [KnownType(typeof(GeoLocation))]
    [KnownType(typeof(NumberField))]
    [KnownType(typeof(PictureAttachment))]
    [KnownType(typeof(TextField))]
    [KnownType(typeof(LabelField))]
    [KnownType(typeof(FormSection))]
    [KnownType(typeof(FormField))]
    [DataContract(IsReference = true)]
    public abstract partial class FormElement
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FormElement" /> class.
        /// </summary>
        public FormElement()
        {
            this.IsEnabled = true;
        }

        /// <summary>
        /// Gets or sets the key of the field.
        /// </summary>
        [System.Xml.Serialization.XmlIgnore, System.Runtime.Serialization.DataMember]
        public virtual string Key { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this element is enabled or not.
        /// </summary>
        [System.Xml.Serialization.XmlIgnore, System.Runtime.Serialization.DataMember]
        [Description("Determines if this element is enabled or not. Default value is true.")]
        public virtual bool IsEnabled { get; set; }

        /// <summary>
        /// Validates the element.
        /// </summary>
        /// <returns>The validation result.</returns>
        public virtual IEnumerable<string> Validate()
        {
            return Enumerable.Empty<string>();
        }
    }
}
